using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using WL.Think.Abp.EntityFrameworkCore;

namespace WL.Think.Abp;

/// <summary>
/// 用来实现数据库迁移的抽象类。
/// </summary>
/// <typeparam name="TDbContext"></typeparam>
public abstract class ThinkEfCoreDbSchemaMigrator<TDbContext> : IThinkDbSchemaMigrator, ITransientDependency where TDbContext : AppDbContextBase<TDbContext>
{
    protected readonly IServiceProvider ServiceProvider;

    protected ThinkEfCoreDbSchemaMigrator(IServiceProvider serviceProvider)
    {
        ServiceProvider = serviceProvider;
    }

    public virtual async Task MigrateAsync()
    {
        await ServiceProvider.GetRequiredService<TDbContext>().Database.MigrateAsync();
    }
}
